package com.china08.yxyapi.api.manage.sch.platform.website.image;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.sws.SwsSettingSliders;
import com.china08.yxyapi.model.YxyApiPageReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.SwsSettingSlidersRepository;

@CrossOrigin
@RestController("ImageListController")
public class ImageListController extends YxyApiBaseController {

    @Autowired
    SwsSettingSlidersRepository swsSettingSlidersRepository;

    @RequestMapping(value = "/api_yw/manage/sch/platform/website/image/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object precess(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {

        // 当前用户学校
        String schoolId = getProfile(request, response).getSchoolId();

        Pageable pageable = reqModel.getPageable(Direction.DESC, "orderNum");

        Page<SwsSettingSliders> page = swsSettingSlidersRepository.findBySchoolId(schoolId, pageable);
        RespModel respModel = new RespModel();
        respModel.list = page.getContent();
        respModel.totalElements = page.getTotalElements();
        respModel.number = page.getNumber();
        return respModel;
    }

    protected static class ReqModel extends YxyApiPageReqModel {
    }

    protected static class RespModel extends YxyApiRespModel {
        public List<SwsSettingSliders> list;
        public long totalElements;
        public long number;
    }
}
